﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Performance;

namespace PerformanceCompareWithDifferentMocks
{
    class Program
    {
        static void Main(string[] args)
        {
            /*
            TestForFail();
            TestForSuccess();
            */ 

            Console.ReadLine();
        }

        private static void TestForFail()
        {
            var moq = new UsingMoq.FailingTest();
            var rhino = new UsingRhinoMocks.FailingTest();
            var isolator = new UsingTypeMock.FailingTest();

            Console.WriteLine("Case 1. Some unexpected method gets invoked.");
            Win32Wrapcs.Run("Moq".PadRight(15), moq.CallOnceExpectNever);
            Win32Wrapcs.Run("Rhino".PadRight(15), rhino.CallOnceExpectNever);
            Win32Wrapcs.Run("Isolator".PadRight(15), isolator.CallOnceExpectNever);
            Console.WriteLine("Press <enter> to continue...");
            Console.ReadLine();

            Console.WriteLine("Case 2. Some expected method is not invoked.");
            Win32Wrapcs.Run("Moq".PadRight(15), moq.CallNeverExpectOnce);
            Win32Wrapcs.Run("Rhino".PadRight(15), rhino.CallNeverExpectOnce);
            Win32Wrapcs.Run("Isolator".PadRight(15), isolator.CallNeverExpectOnce);
            Console.WriteLine("Press <enter> to continue...");
            Console.ReadLine();

            Console.WriteLine("Case 3. Some expected method is not invoked - custom message.");
            Win32Wrapcs.Run("Moq".PadRight(15), moq.FailWithCustomMessage);
            Win32Wrapcs.Run("Rhino".PadRight(15), rhino.FailWithCustomMessage);
            Win32Wrapcs.Run("Isolator".PadRight(15), isolator.FailWithCustomMessage);
            Console.WriteLine("Press <enter> to continue...");
            Console.ReadLine();

            Console.WriteLine("Case 4. Expected method is invoked but parameters were incorrect.");
            Win32Wrapcs.Run("Moq".PadRight(15), moq.CallExpectedWithWrongParameters);
            Win32Wrapcs.Run("Rhino".PadRight(15), rhino.CallExpectedWithWrongParameters);
            Win32Wrapcs.Run("Isolator".PadRight(15), isolator.CallExpectedWithWrongParameters);

            Console.WriteLine("Press <enter> to exit...");
        }

        private static void TestForSuccess()
        {
            // Measure how long it takes to fetch all the keys exactly once
            var timer = new MultiSampleCodeTimer(10, 100);
            Console.WriteLine("Data units of msec resolution = " + MultiSampleCodeTimer.ResolutionUsec.ToString("f6") + " usec");
            //timer.OnMeasure = MultiSampleCodeTimer.PrintStats; // Uncomment if you want to see detailed stats.

            var moq = new UsingMoq.ShoppingCartTest();
            var rhino = new UsingRhinoMocks.ShoppingCartTest();
            var isolator = new UsingTypeMock.ShoppingCartTest();

            Console.WriteLine("\nMocking methods.");
            timer.Measure("Moq".PadRight(15), () => { moq.Test1_MockedMethod(); });
            timer.Measure("Rhino".PadRight(15), () => { rhino.Test1_MockedMethod(); });
            timer.Measure("Isolator".PadRight(15), () => { isolator.Test1_MockedMethod(); });

            Console.WriteLine("\nMocking events.");
            timer.Measure("Moq".PadRight(15), () => { moq.Test2_MockedEvent(); });
            timer.Measure("Rhino".PadRight(15), () => { rhino.Test2_MockedEvent(); });
            timer.Measure("Isolator".PadRight(15), () => { isolator.Test2_MockedEvent(); });

            Console.WriteLine("\nMocking properties.");
            timer.Measure("Moq".PadRight(15), () => { moq.Test3_MockedProperty(); });
            timer.Measure("Rhino".PadRight(15), () => { rhino.Test3_MockedProperty(); });
            timer.Measure("Isolator".PadRight(15), () => { isolator.Test3_MockedProperty(); });

            Console.WriteLine("\nMocking method arguments.");
            timer.Measure("Moq".PadRight(15), () => { moq.Test4_MockedArgument(); });
            timer.Measure("Rhino".PadRight(15), () => { rhino.Test4_MockedArgument(); });
            timer.Measure("Isolator".PadRight(15), () => { isolator.Test4_MockedArgument(); });

            Console.WriteLine("\nPartial mocks.");
            timer.Measure("Moq".PadRight(15), () => { moq.Test5_PartialMocks(); });
            timer.Measure("Rhino".PadRight(15), () => { rhino.Test5_PartialMocks(); });
            timer.Measure("Isolator".PadRight(15), () => { isolator.Test5_PartialMocks(); });

            Console.WriteLine("\nRecursive mocks.");
            timer.Measure("Moq".PadRight(15), () => { moq.Test6_RecursiveMocks(); });
            timer.Measure("Rhino".PadRight(15), () => { rhino.Test6_RecursiveMocks(); });
            timer.Measure("Isolator".PadRight(15), () => { isolator.Test6_RecursiveMocks(); });
        }
    }
}
